local MakeAccessor = UI.MakeAccessor
local MakeTypeSetter = UI.MakeTypeSetter
local CheckWidgetType = UI.CheckWidgetType
local CheckArgType = UI.CheckArgType
local CheckArgWidget = UI.CheckArgWidget
local IsWidgetType = UI.IsWidgetType

--[[ FontInstance ]]--
local FontInstance = UI.NewWidgetType("FontInstance", "UIObject")

FontInstance.parameters = {
	font = "Fonts\\FRIZQT__.TTF",
	height = 12,
	flag = "",
	fparent = nil,
	justifyh = "LEFT",
	justifyv = "TOP",
	shadowred = 0,
	shadowgreen = 0,
	shadowblue = 0,
	shadowalpha = 1,
	shadowoffsetx = 0,
	shadowoffsety = 0,
	textcolorred = 1,
	textcolorgreen = 1,
	textcolorblue = 1,
	textcoloralpha = 1,
}

-- MakeAccessor("FontInstance", "GetFontObject", "fparent")
MakeAccessor("FontInstance", "GetJustifyH", "justifyh")
MakeTypeSetter("FontInstance", "SetJustifyH", "justifyh", "string")
MakeAccessor("FontInstance", "GetJustifyV", "justifyv")
MakeTypeSetter("FontInstance", "SetJustifyV", "justifyv", "string")
MakeAccessor("FontInstance", "GetShadowColor", {"shadowred", "shadowgreen", "shadowblue", "shadowalpha"})
MakeTypeSetter("FontInstance", "SetShadowColor", {"shadowred", "shadowgreen", "shadowblue", "shadowalpha"}, {"number", "number", "number", {"number", "nil"}})
MakeAccessor("FontInstance", "GetShadowOffset", {"shadowoffsetx", "shadowoffsety"})
MakeTypeSetter("FontInstance", "SetShadowOffset", {"shadowoffsetx", "shadowoffsety"}, {"number", "number"})
MakeAccessor("FontInstance", "GetSpacing", "spacing")
MakeTypeSetter("FontInstance", "SetSpacing", "spacing", "number")
MakeAccessor("FontInstance", "GetTextColor", {"textcolorred", "textcolorgreen", "textcolorblue", "textcoloralpha"})
MakeTypeSetter("FontInstance", "SetTextColor", {"textcolorred", "textcolorgreen", "textcolorblue", "textcoloralpha"}, {"number", "number", "number", {"number", "nil"}})

function FontInstance.prototype:GetFont()
	CheckWidgetType("FontInstance:GetFont", self, "FontInstance")
	local t = UI.params[self]
	if t.fparent then
		return t.fparent:GetFont()
	end
	return t.font, t.height, t.flag
end

function FontInstance.prototype:SetFont(font, height, flag)
	CheckWidgetType("FontInstance:SetFont", self, "FontInstance")
	CheckArgType("FontInstance:SetFont", 2, "font", "string", font)
	CheckArgType("FontInstance:SetFont", 3, "height", "number", height)
	CheckArgType("FontInstance:SetFont", 4, "flags", {"string", "nil"}, flag)
	local t = UI.params[self]
	t.fparent = nil
	t.font = font
	t.height = height
	t.flag = flag
end

local copyparams = {
	font = true,
	height = true,
	flag = true,
	justifyh = true,
	justifyv = true,
	shadowred = true,
	shadowgreen = true,
	shadowblue = true,
	shadowalpha = true,
	shadowoffsetx = true,
	shadowoffsety = true,
	textcolorred = true,
	textcolorgreen = true,
	textcolorblue = true,
	textcoloralpha = true,
}

function FontInstance.prototype:GetFontObject()
	return UI.params[self].fparent or self
end

function FontInstance.prototype:SetFontObject(fontObject)
	CheckWidgetType("FontInstance:SetFontObject", self, "FontInstance")
	if fontObject == nil then
		print("FontInstance:SetFontObject(nil)", debug.traceback())
	end
	if type(fontObject) == "string" then
		fontObject = UI.fonts[fontObject]
	end
	CheckArgWidget("FontInstance:SetFontObject", 2, "fontObject", "FontInstance", fontObject)
	UI.params[self].fparent = fontObject
	for k in pairs(copyparams) do
		UI.params[self][k] = UI.params[fontObject][k]
	end
end

